package com.leetcode.LC_MED;

public class LC338 {
    public int[] countBits(int num) {

        int[] ints = new int[num + 1];
        for (int i = 0; i <= num; i++) {
            int count = 0;
            String s = Integer.toBinaryString(i);
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == '1') {
                    count++;
                }
            }
            ints[i] = count;

        }
        return ints;
    }

    public int[] countBits2(int num) {

        int[] ints = new int[num + 1];
        ints[0] = 0;
        for (int i = 1; i <= num; i++) {
            if (i % 2 == 1) {
                ints[i] = ints[i - 1] + 1;
            } else {
                ints[i] = ints[i / 2];
            }
        }
        return ints;
    }

    public int[] countBits3(int num) {

        int[] ints = new int[num + 1];
        ints[0] = 0;
        for (int i = 1; i <= num; i++) {
            if (i % 2 == 1) {
                ints[i] = ints[i - 1] + 1;
            } else {
                ints[i] = ints[i / 2];
            }
        }
        return ints;
    }

    public static void main(String[] args) {
        System.out.println(8 & 12);
    }
}
